﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using ZH.Infrastructure.Dto.Request.Login;
using ZH.Infrastructure.Dto.Response.admin;
using ZH.Infrastructure.Dto.Response;
using ZH.Infrastructure.Tools;
using ZH.Service.Interface;
using ZH.Service.Instance;
using ZH.Infrastructure.Dto.Request.Tech;
using ZH.Infrastructure.Dto.Request.Yuyue;
using ZH.Infrastructure.EFCore.MySql;
using Mysqlx.Crud;
using Org.BouncyCastle.Asn1.Mozilla;
using ZH.Infrastructure.Dto.Response.Promotion;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Collections.Generic;

namespace ZH.Api.Admin.Controllers.Mobile
{
    /// <summary>
    /// 移动端推广
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]


    public class PromotionController : Controller
    {

        public readonly I_Mobile_Service _i_mobile_Service;

        private readonly I_Promotion_Service _i_Promotion_Service;

        public PromotionController(I_Promotion_Service i_Promotion_Service, I_Mobile_Service i_Mobile_Service)
        {

            _i_Promotion_Service = i_Promotion_Service;
            _i_mobile_Service = i_Mobile_Service;


        }

        /// <summary>
        /// 获取推广文案
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_copywriting(int? page = 1, int? limit = 10, string? key = "")
        {
            var result = await _i_Promotion_Service.Get_copywriting(page, limit, key);
            return Ok(result);
        }

        /// <summary>
        /// 添加文案
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_copywriting(Copywriting_Response_Dto dto)
        {
            var result = await _i_mobile_Service.Add_copywriting(dto);
            return Ok(result);
        }


        /// <summary>
        /// 删除文案
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> delete_copywriting(string? id)
        {
            var result = await _i_mobile_Service.delete_copywriting(id);
            return Ok(result);
        }


        /// <summary>
        /// 修改文案
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> update_copywriting(Copywriting_Response_Dto dto)
        {
            var result = await _i_mobile_Service.update_copywriting(dto);
            return Ok(result);
        }




        /// <summary>
        /// 获取推广海报
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_poster()
        {
            var result = await _i_Promotion_Service.Get_poster();
            return Ok(result);
        }



        /// <summary>
        /// 获取推广记录
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_record(string? id)
        {
            var code = Response.HttpContext.User.Identity?.Name;
            var user = _i_mobile_Service.Check_Login(code, "");
            var result = await _i_Promotion_Service.Get_record(user, id);
            return Ok(result);
        }


        /// <summary>
        /// 获取收益
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_revenue()
        {
            var code = Response.HttpContext.User.Identity?.Name;
            var user = _i_mobile_Service.Check_Login(code, "");
            var result = await _i_Promotion_Service.Get_revenue(user.id);
            return Ok(result);
        }

        /// <summary>
        /// 获取推广人数数量
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_promotion_quantity()
        {
            var code = Response.HttpContext.User.Identity?.Name;
            var user = _i_mobile_Service.Check_Login(code, "");
            var result = await _i_Promotion_Service.Get_promotion_quantity(user.id);
            return Ok(result);
        }


        /// <summary>
        /// 获取推广记录·管理端
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_GL_record(int? page = 1, int? limit = 10, string? key = "")
        {
            var result = await _i_Promotion_Service.Get_GL_record(page, limit, key);
            return Ok(result);
        }


        /// <summary>
        /// 佣金结算或者拒绝·管理端
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Sr_record(SrRecordRequest ls)
        {
            var result = await _i_Promotion_Service.Sr_record(ls.Id,ls.Cz);
            return Ok(result);

        }

        public class SrRecordRequest
        {
            public string? Id { get; set; }  // 对应前端传递的id
            public string? Cz { get; set; }  // 对应前端传递的cz（操作类型）
        }


        
    }
}

